Skip to content

Keep the default Windows Ctrl-C termination while loading - #178

Open
mark-yong wants to merge 1 commit into
NVIDIA:mainfrom
mark-yong:fix-113-windows-loading
Open

mark-yong wants to merge 1 commit into
NVIDIA:mainfrom
mark-yong:fix-113-windows-loading

Conversation

@mark-yong

@mark-yong mark-yong commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Refs #113

Request

flare run on Windows previously installed its console control handler (stop_console) via SetConsoleCtrlHandler in run() (flare-cli/src/main.rs) before core download, trust verification, and GPU model loading. Because stop_console returns 1 ("handled") for CTRL_C_EVENT and CTRL_BREAK_EVENT, it suppressed Windows's default process termination while nothing checked STOP until the serving loop (distribution and launch are #[cfg(unix)], and Windows rejects multi-host flags). A Ctrl-C during download or loading was therefore swallowed on Windows, leaving forced process termination as the only exit path.

Installing the handler after loaded.start() in serve_local() rather than in run(), serve(), or before loaded.start() avoids keeping Ctrl-C suppressed where nothing polls STOP:

  • Windows rejects multi-host flags in run(), so serve() delegates local runs to serve_local() and never enters its multi-host Server::start() path on Windows.
  • Installing before loaded.start() would suppress Ctrl-C while LoadedSession::start() calls Server::start and executes startup tuning graphs (helios/src/execution/transport.rs) under a 120-second completion deadline before the serving loop starts.
  • Returning an error if SetConsoleCtrlHandler fails after loaded.start() remains safe because LoadedSession::start() guards the model owner with DrainGuard and ServingSession::drop() calls close() (helios/src/server/session.rs), draining or retaining GPU storage rather than releasing an undrained owner.

Change

  • flare-cli/src/main.rs: Removed the early #[cfg(windows)] SetConsoleCtrlHandler(Some(stop_console), 1) registration from run(), and added it in serve_local() immediately after loaded.start() alongside the #[cfg(unix)] SIGINT/SIGTERM block, keeping the == 0 OS-error check. Left serve() unchanged.
  • docs/windows.md: Rewrote the Ctrl-C sentence in place to state that Ctrl-C and Ctrl-Break end loading immediately and drain native work before releasing CUDA resources once serving has started.

Expected Result

On Windows, Ctrl-C and Ctrl-Break keep the default immediate process termination throughout core download, verification, loading, and server startup, and drain native replay before releasing CUDA resources once serving has started. Unix builds and behavior are unchanged.

Validation

On a Linux x86_64 host against commit 20d2c655, cargo test --locked --release --manifest-path flare-cli/Cargo.toml (with CAP_DAC_OVERRIDE dropped via setpriv so read-only cache-directory tests enforce EACCES) passed (exit 0) across all five test binaries:

  • src/main.rs unit tests: 201 passed, 0 failed, 3 ignored (export_signed_payload_distribution_fixture, receive_rank_accepts_old_metadata_with_empty_platform, serve_ring_transfer_fixture)
  • tests/cache_commands.rs: 9 passed, 0 failed, 0 ignored
  • tests/cli.rs: 6 passed, 0 failed, 0 ignored
  • tests/inspect.rs: 4 passed, 0 failed, 0 ignored
  • tests/unverified_payload.rs: 7 passed, 0 failed, 0 ignored
  • Total: 227 passed, 0 failed, 3 ignored.

Cross-compilation checking from Linux against commit 20d2c655 via cargo xwin check --locked --release --manifest-path flare-cli/Cargo.toml --target x86_64-pc-windows-msvc exited 0, confirming Rust compilation of flare-cli including the #[cfg(windows)] SetConsoleCtrlHandler change with zero errors in flare-cli/src/main.rs. Full cross-linking via cargo xwin build --locked --release --manifest-path flare-cli/Cargo.toml --target x86_64-pc-windows-msvc compiled flare-cli Rust objects cleanly and failed at lld-link (exit 101) due to pre-existing cross-build mismatches unrelated to flare-cli/src/main.rs: default CRT linking hit a RuntimeLibrary mismatch between libflare_selene (MD_DynamicRelease) and libesaxx_rs (MT_StaticRelease), while RUSTFLAGS="-C target-feature=+crt-static" hit undefined __cpu_model and __cpu_features2 symbols referenced by libflare_selene.

Limitations

  • Windows executable linking (lld-link failed on libflare_selene / libesaxx_rs as noted above) and Windows native test execution (windows-2022 CI triggered on push) were not run locally.
  • Live Windows flare run CORE execution demonstrating immediate exit on Ctrl-C during loading and clean drain after "Start server" was not run.

Discord: myong_acct

@original-el8 original-el8 added area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. bug Something isn't working priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness. labels Nov 5, 2026
@original-el8

original-el8 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Updated mergeability check: head 85fb08c merges cleanly into main 5fd4070. There is no local source conflict blocking this Windows console-handler change, so the earlier GitHub conflict indication should not be treated as an outstanding rebase request. Native Windows Ctrl-C behavior during loading and orderly shutdown still requires its platform-specific validation; no Windows run was performed for this update.

@yatesdr yatesdr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restoring the default Ctrl-C exit before serving is right for main's Windows path, but this edits a file that no longer exists, and nothing was compiled or run on Windows.

  1. Port it to main. flare/src/main.rs moved to flare-cli/src/main.rs in fa15828. On main, Windows serves through serve_local (flare-cli/src/main.rs:630), and the console handler is installed at line 148; make the change there, before the server starts. GitHub reports the branch as conflicting.
  2. Build and run it on Windows. Post the output of cargo check --manifest-path flare-cli/Cargo.toml --target x86_64-pc-windows-msvc, and a flare run CORE session in which Ctrl-C during loading exits at once and Ctrl-C after "Start server" drains.
  3. Docs. docs/windows.md:141-142 says Ctrl-C drains native work. State that before the server starts, Ctrl-C ends the process.
  4. CONTRIBUTING.md requires Signed-off-by; 85fb08c has none. Redo the design acknowledgment after porting; 1c01 matches the old base.

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 178.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review for Agents · Value Proposition · Case File

Recommendation: Changes Requested

The diagnosis behind PR #178 is correct: stop_console returns 1 ("handled") for Ctrl-C/Ctrl-Break, so it suppresses the default termination, and on Windows nothing reads STOP before the serving loop (mod distribution / mod launch are #[cfg(unix)], flare-cli/src/main.rs:17-31). But the change cannot land as written: it edits a file main no longer has, and the placement it argues for cannot simply be ported.

Blockers:

  • The only changed file, flare/src/main.rs, was moved to flare-cli/src/main.rs in fa158284 (2026-11-09), after this branch point (902c88e). The block it deletes still exists verbatim at flare-cli/src/main.rs:187-192 → rebase and delete it there; all 14 diff lines are currently inert.
  • A verbatim port into serve() fixes nothing: Windows rejects every multi-host flag (flare-cli/src/main.rs:178-186), so serve always returns into serve_local (:602-604) and the Server::start the PR targets (:630-648) never runs on Windows → one registration site in serve_local, around loaded.start() (:702); do not add a second in serve.

Should fix:

  • Register after loaded.start(), beside the Unix #[cfg(unix)] block (flare-cli/src/main.rs:705-709). Before the start it re-swallows Ctrl-C for up to minutes while tuning graphs spin under a 120 s deadline with no STOP reader (helios/src/execution/transport.rs:474-481, 598-604; Server::start blocks at helios/src/server.rs:417), which also falsifies the description's "Ctrl-C during Server::start … exits at once". The drain worry is already covered by DrainGuard (helios/src/server/session.rs:96-108, 110-133), so no mem::forget is needed. Fallback only if the before-start site is kept: have stop_console return 0 once STOP is already set, so a second Ctrl-C terminates.
  • docs/windows.md:141-142 — same-length rewrite, no new section: "Ctrl-C and Ctrl-Break end loading immediately, and drain native work once serving has started."
  • Post the Windows compile result: .github/workflows/native-serving.yml (not opened) already builds (:45) and tests (:73) flare-cli on windows-2022 (:20-21) for every pull_request (:6). Keep only the live Ctrl-C session as the explicitly unrun check.
  • Correct two claims: issue Loader ignores Control C to cancel loading #113 has no Windows reproduction (its reporter was on Linux), and "instead of dropping the package owner without a confirmed drain" does not describe the old site, where no package had been loaded yet.
  • One mechanics pass after the rebase: Discord: line (AGENTS.md:142-153), Signed-off-by (CONTRIBUTING.md:9-11), design-review digest recomputed over the staged doc (docs/design-review.md:178-196; the current 1c01 matches the old base).

Subtract / Simplify:

Could remove ~14 of +8 added lines (the whole +8/−6 diff lands in a deleted file); the ported equivalent adds ~7, of which ~1 is cuttable:

  • flare/src/main.rs:574-575 — delete "A registration failure must return before replay starts."; it restates the return Err and is backwards at the before-start site (~1 line).
  • Whole diff — a pure relocation: no install_ctrl_handler helper, no heliopause::processes_windows::CliSignals reuse (~0 lines, avoids a new dependency and a second Ctrl-C policy).
  • docs/windows.md:141-142 — rewrite in place, not an added paragraph (~0 net lines).
  • flare/src/main.rs:576-581 — keep the == 0 error check; dropping it would suppress an OS error (AGENTS.md:182-186).

Nits:

3 nits — comment placement between phase and context_tokens; optional ANSI/cursor restore (\x1b[0m\x1b[?25h\r\n) before a default-terminated exit; description paths plus stating the early registration is removed, not duplicated.

Full detail, evidence and the verified non-findings: see the case file.

To opt out, include #autobot:ignore in your post or comment.

@mark-yong
mark-yong force-pushed the fix-113-windows-loading branch from 85fb08c to 43c6ea7 Compare November 28, 2026 19:36
@mark-yong

Copy link
Copy Markdown
Contributor Author

@yatesdr @flare-autobot Rebased onto nvidia/main (167f22c8, commit 43c6ea78) and updated PR #178:

  1. Ported to flare-cli/src/main.rs (serve_local): Removed the early #[cfg(windows)] SetConsoleCtrlHandler(Some(stop_console), 1) registration from run() and moved it into serve_local(). serve() is untouched because run() (flare-cli/src/main.rs:178-186) rejects multi-host flags on Windows and serve() (:596-598) dispatches local runs into serve_local().
  2. Placement after loaded.start() (flare-cli/src/main.rs:696-710): Installed the Windows handler immediately after loaded.start() alongside the #[cfg(unix)] SIGINT/SIGTERM block rather than before loaded.start(), because LoadedSession::start() calls Server::start (helios/src/server/session.rs:60-69) and runs startup tuning graphs under a 120-second completion deadline without checking STOP (helios/src/execution/transport.rs:739-777). Returning on SetConsoleCtrlHandler == 0 after loaded.start() remains safe because LoadedSession::start() guards the model owner in DrainGuard and ServingSession::drop() calls close() (helios/src/server/session.rs:57,104-133).
  3. Updated docs/windows.md:141-142: Rewrote the Ctrl-C sentence in place to state that Ctrl-C and Ctrl-Break end loading immediately and drain native work before releasing CUDA resources once serving has started.
  4. Trailers and PR description: Added Signed-off-by: Mark Yong <mark-yong@users.noreply.github.com>, refreshed Design-Signed-Off-By against docs/design-review.md, added Discord: myong_acct, and updated the PR description to match 43c6ea78.
  5. Validation status: On commit 43c6ea78, Linux x86_64 cargo test --locked --release --manifest-path flare-cli/Cargo.toml (with CAP_DAC_OVERRIDE dropped) passed (221 passed, 0 failed, 3 ignored). We are unable to test on Windows locally, so cargo check --manifest-path flare-cli/Cargo.toml --target x86_64-pc-windows-msvc / windows-2022 CI checks (which will run on push via .github/workflows/native-serving.yml) and live Windows flare run CORE Ctrl-C verification across loading and "Start server" shutdown remain unrun.

@mark-yong
mark-yong requested a review from yatesdr November 28, 2026 19:37
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

The code and documentation diff at 43c6ea78 is correct and ready to merge, but two non-code items remain: the PR description still contradicts the head commit, and the #[cfg(windows)] change has not been compiled on Windows.

  • Blockers: 0
  • Should fix: 2
  • Subtractive suggestions: 0
  • Nits: 0

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

`flare run` on Windows previously registered `stop_console` via
`SetConsoleCtrlHandler` in `run()` (`flare-cli/src/main.rs`) before core
download, trust verification, and GPU model loading. Because `stop_console`
returns `1` ("handled") for `CTRL_C_EVENT` and `CTRL_BREAK_EVENT`, it
suppressed Windows's default process termination while nothing checked `STOP`
until the serving loop (`distribution` and `launch` are `#[cfg(unix)]`, and
Windows rejects multi-host flags). A Ctrl-C during download or loading was
therefore swallowed, leaving forced termination as the only exit path.

Installing the handler after `loaded.start()` in `serve_local()` rather than
earlier avoids keeping Ctrl-C suppressed in two places that never poll
`STOP`: Windows rejects multi-host flags before `serve()` and routes local
runs into `serve_local()`, while `loaded.start()` invokes `Server::start`
and runs startup tuning graphs (`helios/src/execution/transport.rs`) under a
120-second completion deadline before the serving loop starts. Returning an
error if `SetConsoleCtrlHandler` fails after `loaded.start()` remains safe
because `LoadedSession::start()` wraps the model owner in `DrainGuard` and
`ServingSession::drop()` calls `close()` (`helios/src/server/session.rs`),
draining or retaining GPU storage rather than releasing an undrained owner.

Removed the early `#[cfg(windows)]` `SetConsoleCtrlHandler(Some(stop_console), 1)`
block from `run()` in `flare-cli/src/main.rs` and added it in `serve_local()`
immediately after `loaded.start()` alongside the `#[cfg(unix)]` signal block,
retaining the `== 0` OS-error check. Left `serve()` unchanged and rewrote
the Ctrl-C sentence in `docs/windows.md` in place to state that Ctrl-C and
Ctrl-Break end loading immediately and drain native work before releasing
CUDA resources once serving has started.

On Windows, Ctrl-C and Ctrl-Break now preserve default immediate termination
throughout download, verification, loading, and server startup, and drain
native replay before releasing CUDA resources once serving begins. Unix
behavior is unchanged.

On a Linux x86_64 host against this commit's tree, `cargo test --locked
--release --manifest-path flare-cli/Cargo.toml` (with `CAP_DAC_OVERRIDE`
dropped via `setpriv` so read-only cache permission tests enforce `EACCES`)
passed (`exit 0`) across all five test binaries: `src/main.rs` unit tests
(201 passed, 0 failed, 3 ignored for multi-host hardware/payload fixtures),
`tests/cache_commands.rs` (9 passed), `tests/cli.rs` (6 passed),
`tests/inspect.rs` (4 passed), and `tests/unverified_payload.rs` (7 passed),
totaling 227 passed, 0 failed, and 3 ignored. Cross-compilation checking
from Linux via `cargo xwin check --locked --release --manifest-path
flare-cli/Cargo.toml --target x86_64-pc-windows-msvc` passed (`exit 0`),
verifying compilation of `flare-cli` including the `#[cfg(windows)]`
`SetConsoleCtrlHandler` path. Full cross-linking via `cargo xwin build
--locked --release` failed at `lld-link` (`exit 101`) due to pre-existing
cross-build mismatches unrelated to `flare-cli/src/main.rs`: default CRT
linking hit a `RuntimeLibrary` mismatch between `libflare_selene`
(`MD_DynamicRelease`) and `libesaxx_rs` (`MT_StaticRelease`), while
`RUSTFLAGS="-C target-feature=+crt-static"` hit undefined `__cpu_model` and
`__cpu_features2` symbols referenced by `libflare_selene`. Limitations:
Windows executable linking, Windows native test execution, and live Windows
`flare run CORE` Ctrl-C verification (immediate termination during loading
and clean drain after `"Start server"`) were not run.

Refs: NVIDIA#113
Signed-off-by: Mark Yong <mark-yong@users.noreply.github.com>
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
@mark-yong
mark-yong force-pushed the fix-113-windows-loading branch from 43c6ea7 to 20d2c65 Compare November 30, 2026 08:56
@mark-yong

Copy link
Copy Markdown
Contributor Author

@yatesdr @flare-autobot Rebased onto nvidia/main (0a8c20f4, commit 20d2c655) and updated PR #178:

  1. Moved handler registration into serve_local() after loaded.start() (flare-cli/src/main.rs:704-710): Removed the early #[cfg(windows)] SetConsoleCtrlHandler(Some(stop_console), 1) registration from run() and placed it in serve_local() immediately after loaded.start() (:696) alongside the #[cfg(unix)] SIGINT/SIGTERM block. serve() is untouched because run() (flare-cli/src/main.rs:178-186) rejects multi-host flags on Windows and serve() (:597) dispatches local runs into serve_local(), while LoadedSession::start() executes startup tuning graphs under a 120-second deadline (helios/src/execution/transport.rs:759,772) and guards the model owner in DrainGuard so ServingSession::drop() calls close() (helios/src/server/session.rs:57,96,105).
  2. Updated docs/windows.md:141-142: Rewrote the Ctrl-C sentence in place to state that Ctrl-C and Ctrl-Break end loading immediately and drain native work before releasing CUDA resources once serving has started.
  3. Updated live PR body: Synced the PR description to match 20d2c655 with Discord: myong_acct and current validation/limitations.
  4. Validation (20d2c655):
    • Linux x86_64 cargo test --locked --release --manifest-path flare-cli/Cargo.toml (with CAP_DAC_OVERRIDE dropped via setpriv) passed (227 passed, 0 failed, 3 ignored).
    • Windows cross-compilation check from Linux via cargo xwin check --locked --release --manifest-path flare-cli/Cargo.toml --target x86_64-pc-windows-msvc exited 0, confirming Rust compilation of flare-cli including the #[cfg(windows)] SetConsoleCtrlHandler block. Full cross-linking via cargo xwin build --locked --release failed at lld-link (exit 101) due to pre-existing libflare_selene vs libesaxx_rs CRT / __cpu_model cross-build mismatches unrelated to flare-cli/src/main.rs.
    • Unable to test natively on Windows locally, so Windows native tests (windows-2022 CI on push) and live Windows flare run CORE Ctrl-C verification across loading and "Start server" shutdown remain unrun.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

Minimal root-cause fix that relocates the Windows console handler to match Unix placement, restoring Ctrl-C/Break during download, loading, and startup. Docs and code are consistent; only an optional live Windows smoke test remains.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 0 · Nits: 1
Walkthrough
  • flare-cli/src/main.rs:178-187: Removed the early #[cfg(windows)] SetConsoleCtrlHandler(Some(stop_console), 1) registration from run(), which was swallowing Ctrl-C throughout download, verification, and GPU loading.
  • flare-cli/src/main.rs:704-710: Re-installed the handler inside serve_local() immediately after loaded.start(), preserving the == 0 last_os_error() check and matching the Unix SIGINT/SIGTERM placement.
  • serve() is intentionally untouched; Windows rejects multi-host flags and always dispatches to serve_local(). Registering after loaded.start() also avoids swallowing Ctrl-C during startup tuning graphs.
  • docs/windows.md:141-142: Updated the Ctrl-C sentence to state that Ctrl-C and Ctrl-Break end loading immediately and drain native work before releasing CUDA resources once serving starts.
Merge Risk: Low · up to 20d2c65
  • Confined to a 7-line #[cfg(windows)] startup block in flare-cli/src/main.rs:704-710 and a two-line docs update in docs/windows.md:141-142; Unix builds and behavior are untouched.
  • No hot-path, concurrency, memory, I/O, or scheduler impact: registration runs once at startup before the serving loop.
  • Failure-path safety verified: if SetConsoleCtrlHandler returns 0, returning Err drops ServingSession, whose Drop calls close() and retains NativeModel via DrainGuard when drain is unconfirmed.
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warnings
  • ✅ Security / malicious screen: Pure relocation of an existing windows-sys SetConsoleCtrlHandler call; no new dependencies, network/filesystem surfaces, or prompt-injection issues.
  • ✅ Charter & value fit: Narrow, minimal-footprint root-cause bug fix matching docs/windows.md; live PR description includes all required sections and Discord: myong_acct.
  • ✅ Related / duplicate / conflict check: Cleanly rebased on 0a8c20f4; no duplicate PRs or conflicts.
  • ⚠️ Tests & verification evidence: Linux tests passed (227 passed, 0 failed, 3 ignored) and cargo xwin check exited 0, but cross-linking failed on pre-existing native library mismatches, no Windows CI check is attached, and live Windows Ctrl-C behavior has not been executed.

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:api Serving API, protocol encoding, tool parsing, and client-visible behavior. bug Something isn't working priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants